package com.xcn.hadoop.webhdfs;


/**
 * WebHDFSConnectionFactory
 * 직접 연결이 필요한 경우 사용
 * 
 * @author jochangmin
 * @since 2013-03-05
 * @version 1.0
 */
public class WebHDFSConnectionFactory
{
	public static final String DEFAULT_HOST = "127.0.0.1";

	public static final int DEFAULT_PORT = 14000;
	
	public static final String DEFAULT_CONTEXT_ROOT = "/webhdfs/v1/";

	public static final String DEFAULT_USERNAME = "DEV";

	public static final String DEFAULT_PROTOCOL = "HTTP";
	
	public static final String DEFAULT_TOKEN = "";
	
	private String host = DEFAULT_HOST;

	private int port = DEFAULT_PORT;

	private String contextRoot = DEFAULT_CONTEXT_ROOT;

	private String username = DEFAULT_USERNAME;
	
	private String token = DEFAULT_TOKEN;

	private WebHDFSConnection webHDFSConnection;

	public WebHDFSConnectionFactory( )
	{
	}

	public WebHDFSConnectionFactory( String host )
	{
		this.host = host;
	}

	public WebHDFSConnectionFactory( String host, int port )
	{
		this.host = host;
		this.port = port;
	}
	
	public WebHDFSConnectionFactory( String host, int port, String contextRoot )
	{
		this.host = host;
		this.port = port;
		this.contextRoot = contextRoot;
	}

	public WebHDFSConnectionFactory( String host, int port, String contextRoot, String username )
	{
		this.host = host;
		this.port = port;
		this.contextRoot = contextRoot;
		this.username = username;
	}

	public WebHDFSConnection getConnection ( )
	{
		String httpfsUrl = DEFAULT_PROTOCOL + "://" + host + ":" + port + contextRoot;
		if ( webHDFSConnection == null )
			webHDFSConnection = new KerberosWebHDFSConnection ( httpfsUrl, username );

		return webHDFSConnection;
	}

	public String getHost ( )
	{
		return host;
	}

	public void setHost ( String host )
	{
		this.host = host;
	}
	
	public int getPort ( )
	{
		return port;
	}
	
	public void setPort ( int port )
	{
		this.port = port;
	}
	
	public String getUsername ( )
	{
		return username;
	}
	
	public void setUsername ( String username )
	{
		this.username = username;
	}

	public String getContextRoot ( )
	{
		return contextRoot;
	}

	public void setContextRoot ( String contextRoot )
	{
		this.contextRoot = contextRoot;
	}
	
	public String getToken ( )
	{
		return token;
	}

	public void setToken ( String token )
	{
		this.token = token;
	}
}
